package main

import "fmt"

type Product interface {
	operation()
}

type ConcreteProductA struct{}

func (ConcreteProductA) operation() {
	fmt.Println("ConcreteProductA operation")
}

type ConcreteProductB struct{}

func (ConcreteProductB) operation() {
	fmt.Println("ConcreteProductB operation")
}

type Creator interface {
	factoryMethod() Product
}

type ConcreteCreatorA struct{}

func (c *ConcreteCreatorA) factoryMethod() Product {
	return &ConcreteProductA{}
}

type ConcreteCreatorB struct{}

func (c *ConcreteCreatorB) factoryMethod() Product {
	return &ConcreteProductB{}
}

func main() {
	// 使用ConcreteCreatorA创建ConcreteProductA
	creatorA := &ConcreteCreatorA{}
	productA := creatorA.factoryMethod()
	productA.operation()
	// output:
	// ConcreteProductA operation

	// 使用ConcreteCreatorB创建ConcreteProductB
	creatorB := &ConcreteCreatorB{}
	productB := creatorB.factoryMethod()
	productB.operation()
	// output:
	// ConcreteProductB operation
}
